Skip to content

Model K: streamline narrow stages and compact head - #288

Merged
phantoslayer21 merged 2 commits into
mainfrom
kl-K/l1-narrow
Nov 19, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
kl-K/l1-narrow

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

What changed

Prewiden the FP16 bias planes and fold weight offsets for Model K's narrow e0, e1, d1, and compact d0 stages. Pack the 32 live d0 head rows into two WMMA tiles and preserve the logical row mapping for the compact and hidden epilogues. Rebind the softmax source digest after the native report gate passed.

Initial timing against eff8ed7

Four alternating ABBA/BAAB blocks per shape, 1,500 frames per leg. A and B used the same runtime build flags and loaded DXIL from disk. A's reviewed phi-fast shaders were verified against the eff8ed7 source tree.

Shape Median B - A (us) Paired block deltas (us) Max A/A (us) Floor (us) Direct FNV
1080p Q -14.500 -13.750, -14.500, -14.500, -14.750 1.500 5.000 1b975fbba17891e3
1440p Q -22.500 -22.500, -22.750, -22.500, -22.000 2.000 5.000 5fb3d1ab49ad8f90

Gates

  • Direct D3D12 route matched both REFS FNVs on all 32 timing legs with zero nonfinite values.
  • Native D3D12 matched all 600 frame hashes and six saved RGBA16F frames at odd, 1080p Q, and 1440p Q against eff8ed7 and REFS. Forced round-to-odd also matched all 600 odd frames and six saved frames. The odd raw state and output comparison matched 516,093,680 bytes, including compact and full head and recurrent state.
  • The CPU and kernel-set run passed all 43 tests, with the GPU-only fixture skipped during that run. The compact pack probe recovered 1,024 weights and 32 biases byte for byte. The native half-widening probe matched 65,536 of 65,536 codes. The exhaustive phi proof covered 1,073,741,824 finite inputs and caught 146 guard-removal errors.
  • The backend-3 k_smx_test=report reproduced 133 of 133 stored HIP hashes in each of mix and round-to-odd, with zero hash or probe mismatches.
  • All 162 DXIL file hashes and provenance entries verified on A and B. The five intended L1 entries changed, with the original gfx1201 ISA and allocation tiers reproduced, 16,384 bytes LDS each, and zero scratch or spills.
  • All four GPU mutants were caught. The e0 bias-next, d0 hidden-swap, e0 W2 weight-next, and uniform-input phi mutants first differed at odd frames 0, 1, 0, and 1, respectively.
  • The leak scan reported zero hits in the eight changed files.

Review fixes

Head 731ba36 passes the compact d0 head and FP32 bias plane as separate D3D12 arguments and preserves the original 48-row head in the shared stage parameters. The hybrid runtime refuses missing or incompatible narrow ports and rejects null argument storage before packing.

The replay passes the original arguments to HIP and supplies the packed weights and bias planes to D3D12. The head row test covers every pixel and hidden channel, and DXC rejects a full-head shader built with the compact bias plane.

Four alternating ABBA/BAAB blocks per shape used 1,500 frames per leg against eff8ed7. The noise floor is max(5 us, twice max A/A).

Shape Median B - A (us) Paired block deltas (us) Max A/A (us) Floor (us) Direct FNV
1080p Q -13.375 -12.500, -13.500, -13.750, -13.250 2.000 5.000 1b975fbba17891e3
1440p Q -23.625 -23.500, -23.750, -23.750, -23.000 3.500 7.000 5fb3d1ab49ad8f90
  • All 32 direct runs matched the reference FNVs with zero nonfinite values. Native D3D12 matched 600 hashes and six saved frames at odd, 1080p Q, and 1440p Q, plus the forced round-to-odd odd run. The raw comparison matched 516,093,680 bytes across 72 buffers and outputs.
  • The backend-3 softmax report matched 133/133 stored HIP hashes in each rounding form with zero hash and probe mismatches.
  • The narrow port check passed 132/132 cases across 11 kernels, including both d1 forms. 13 cases differed only in NaN sign (27 elements). Both controls passed.
  • The D3D12 runtime fixture passed all 38 tests with zero skips. It exercised backends 2 and 3 against HIP, the missing compact port refusal, the corrupt e0 refusal, and round-to-odd at 1440p Q and 4K Performance.
  • The CPU and kernel-set suite passed 54 tests. Its separate tiled-input GPU fixture was skipped in that CPU run. The head pack recovered 1,024 weights and 32 biases. The native widening probe passed all 65,536 half encodings. The exhaustive phi proof covered 1,073,741,824 finite inputs and detected 146 guard-removal errors.
  • All 162 DXIL files and their provenance verified on both builds. RGA/ISA passed for the five changed entries with the same allocation tiers, 16,384 bytes LDS and zero scratch or spills. All four GPU mutants were caught at frames 0, 1, 0 and 1. The commit leak scan reported zero hits.

Use prewidened FP32 bias planes and folded weight offsets in the two-window narrow kernels. Pack the 32 live compact-head rows into two WMMA tiles.

Rebind the K softmax source digest after native D3D12 backend 3 k_smx_test=report reproduced all 133 stored hashes in each of the mix and round-to-odd forms with zero mismatches.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Keep the original 48-row head in KBlkParams and pass the compact
head and bias plane as separate D3D12 arguments. Require the narrow
ports and their argument signatures for hybrid and native contexts.
Refuse missing argument values before hybrid argument packing.

Replay both d1 forms and the compact head against the original HIP
arguments. Check the packed row permutation on the host and reject a
compact-bias full-head shader at compile time.

Rebind the softmax source digest to a47546460b78b46b3ae0775661c6c4160ad20af09b6106c16322f8d164136264.
The native backend-3 k_smx_test=report reproduced 133/133 stored HIP
hashes for each of mix and round-to-odd, with zero hash or probe
mismatches.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 19, 2026 01:20
@phantoslayer21
phantoslayer21 merged commit 11d3bbc into main Nov 19, 2026
10 checks passed
@phantoslayer21
phantoslayer21 deleted the kl-K/l1-narrow branch November 19, 2026 01:20
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 23, 2026
…operands (FP32 bias plane, compact d0 head)

Main's phantoslayer21#288 gave the two-window narrow ports (k_stage2_e0, e1, d1, d1__rodd) a prewidened FP32 bias plane as one more
pointer argument, and d0_hp a compact head (32 live rows in two tiles) plus the plane (three pointers in all), and the
runtime now requires those argument lists for the native context too. The native __g11 forms kept the old lists, so a
native Model K run would have refused to start (require_d3d12_port compares the signature of the __g11 form).

k_block_g11.hlsli's k_block_n11 takes (hidden, blk, bias32, compact_head) under KB_BIAS32 and reads every accumulator
start (embed / expand bias, bo, b2, b1, the merge or head bias, the softmax bias table) from the plane through kn_bias32
(k_block.hlsli's kb_bias32 through kn_ld128, so KN_A16 still decides the alignment hint); the FP16 -> FP32 widening
happened on the host, so every start value is the one wgk_widen8 of the FP16 bias gave. The d0 head reads two packed
tiles from the compact blob and the pixel head and the hidden history take their channels from kb_head_row, as
k_block.hlsli does. Tiles, their order and the roundings are unchanged. KB_BASE_FORM (folded weight offsets) is an
addressing change of the ports and is not taken: the native kernels keep their own loads. The declarations get the
ports' argument lists and defines (KB_BIAS32=1, KB_COMPACT_HEAD_ARG=1).

Verified: build_dx12.py --gfx 11 --model-k builds 18 kernels, exit 0; only k_stage2_e0, e1, d1, d1__rodd and d0_hp
changed (13 of 18 DXIL byte-identical to before). The emulation comparison against the ports follows in the harness
commit.

Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 23, 2026
… find_port user

Main's phantoslayer21#288 added Device::require_d3d12_port, which resolves its kernel through find_port, so in a native run the signature
it compares is the __g11 form's (that is the point of the check, and why the native declarations must carry the ports'
argument lists). The source pin test_the_device_has_one_lookup_point_and_filters_the_manifest counted three users
(definition, prepare, launch); it counts four now.

Verified: clean.tests.test_dev_gfx11_native_k, 12 tests OK (with the declarations of the previous commit: the interface
pin test_every_native_declaration_has_the_launch_interface_of_its_port passes again).

Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 23, 2026
…ports and gives them their operands

Main's narrow ports now differ in their defines (KB_BIAS32, KB_BASE_FORM, KB_COMPACT_HEAD_ARG), so the harness's fixed
groups of "one library per set of defines" no longer hold: k_native_check.groups_by_defines splits the port names by the
declarations' own defines. The launches of the kernels that take phantoslayer21#288's operands (k_native_check.NARROW_BIAS32) get the
FP32 bias plane and d0's compact head appended, built by k_plan_bridge.narrow_d3d12_args from the same weight blob
(k_port_check does the same); the stage check's case files (prepare) carry them as buffers and the manifest tokens
(s184:p19.b32,p and ,p,p,p). The emulator stages the head row table (.inc) next to the headers and turns a const int
table into a constexpr one for its C++ class body.

Verified (CPU, clang++): test_k_native_g11_emu 6 tests, test_k_native_check 1 test and test_dev_gfx11_native_k OK: every
narrow stage, both window counts, three size sets and offsets, both round-to-odd forms and d0's head and hidden history
give the port's bytes (and NumPy within spec 49's limits), the wrong-row-table negative control is caught, and the stage
check's own negative control. Broken on purpose, each caught and restored: the plane's b2 offset moved by 16
(test_native_against_reference_and_port red), d0's head read from the full blob instead of the compact one and a wrong head row
index (test_d0_heads_and_hidden red). Whole 18-module native / gfx11 set: 162 ran, 25 skipped, 0 failures.

Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant